/**
 * @file   1021.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Fri Jul 23 00:29:20 2021
 * 
 * @brief  PAT advanced 1021
 * 
 * 
 */
#include<iostream>
#include<vector>
#include<map>
#include<set>
using namespace std;
class Graph{
private:
    vector<vector<int>> G;
    int Nv;
    int Ne;
    vector<bool> istraversed;
    int depth;
    set<int> maxdepthroot;
    int components;
public:
    Graph();
    void DFS(const int root,int node,int height);
    bool check();//it is a tree or not?
    int getconnectedcomponents();
    int getNv(){
	return Nv;
    }
    void initialize(){
	for(int i=1;i<=Nv;i++){
	    istraversed[i]=false;
	}
    }
    void print1(){
	for(auto it=maxdepthroot.begin();it!=maxdepthroot.end();it++){
	    cout<<*it<<endl;
	}
    }
};
Graph::Graph(){
    cin>>Nv;
    Ne=Nv-1;
    G.resize(Nv+1);
    istraversed.resize(Nv+1);
    for(int i=0;i<Ne;i++){
	int f,r;
	cin>>f>>r;
	G[f].push_back(r);
	G[r].push_back(f);
    }
    depth=0;
    components=0;
}
void Graph::DFS(const int root,int node,int height){
    istraversed[node]=true;
    for(int i=0;i<G[node].size();i++){
	int d=G[node][i];
	if(istraversed[d]==false){
	    DFS(root,d,height+1);
	}
    }
    if(height>depth){
	depth=height;
        maxdepthroot.clear();
        maxdepthroot.insert(root);
    }else if(height==depth){
        maxdepthroot.insert(root);
    }
    return;
}
bool Graph::check(){
    for(int i=1;i<=Nv;i++){
	if(istraversed[i]==false){
	    return false;
	}
    }
    return true;
}
int Graph::getconnectedcomponents(){
    components=1;
    for(int i=1;i<=Nv;i++){
	if(istraversed[i]==false){
	    components++;
	    DFS(i,i,0);
	}
    }
    return components;
}
int main(){
    Graph Gr;
    Gr.DFS(1,1,0);
    if(Gr.check()==true){
	int d=Gr.getNv();
	for(int i=2;i<=d;i++){
	    Gr.initialize();
	    Gr.DFS(i,i,0);
	}
	Gr.print1();
    }else{
	int d=Gr.getconnectedcomponents();
	cout<<"Error: "<<d<<" components"<<endl;
    }
}
